import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Not, Repository  } from 'typeorm';
import { MovieEntity } from 'src/entities/movie.entity';
import { MovieDownloadEntity } from 'src/entities/movieDownload.entity';
@Injectable()
export class MovieListService {
    constructor(
        @InjectRepository(MovieEntity) private readonly movieRepository: Repository<MovieEntity>,
        @InjectRepository(MovieDownloadEntity) private readonly movieDownloadRepository: Repository<MovieDownloadEntity>,
    ) {}
    async getMovieList(body) {
        const { type, pageNum = 0, pageSize = 10 } = body;
        const [list, total] = await this.movieRepository.findAndCount({
            take: pageSize,
            skip: (pageNum - 1) * pageSize,
            where: {
                movieModuleType: type,
            }
        });
       return {
          list,
          total,
       }
    }
    async getMovieDetail(id: number) {
        return await this.movieRepository.findOne({
            where: {
                id,
            },
            relations: {
                downloadUrls: true,
            }
        })
    }
    async downloadMovie(id: number) {
        return await this.movieDownloadRepository.find({
            where: {
                movieId: id,
            },
        })
    }
}
